package com.hospital.pony.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hospital.R;
import com.hospital.pony.model.FriendModel;
import com.hospital.pony.view.RoundedCornerImageView;
import com.squareup.picasso.Picasso;

public class UserListAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private List<FriendModel> list_result;
	private int posIndex;
	private Context mContext;

	public UserListAdapter(Context context, List<FriendModel> list_result) {
		mContext = context;
		inflater = LayoutInflater.from(context);
		this.list_result = list_result;
	}

	@Override
	public int getCount() {
		return list_result.size();
	}

	@Override
	public Object getItem(int position) {
		return list_result.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_doctorquerymessage, null);
			holder = new ViewHolder();
			holder.doctorName = (TextView) convertView.findViewById(R.id.doctorName);
			holder.doctorTime = (TextView) convertView.findViewById(R.id.doctorTime);
			holder.ImageView01 = (RoundedCornerImageView) convertView.findViewById(R.id.ImageView01);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		try {
			holder.doctorName.setText(list_result.get(position).getUserMessage().getUname());
			holder.doctorTime.setText("联系方式：" + list_result.get(position).getUserMessage().getUphone());

			if (list_result.get(position).getUserMessage().getUtype().equals("1")) {
				Picasso.with(mContext).load("http://img5.duitang.com/uploads/item/201602/29/20160229194418_dtkcX.thumb.224_0.jpeg")
						.placeholder(R.drawable.icon_ponydef).into(holder.ImageView01 );
			} else {
				Picasso.with(mContext).load("http://www.qqzhi.com/uploadpic/2014-09-21/140925601.jpg").placeholder(R.drawable.icon_ponydef)
						.into(holder.ImageView01 );
			}

		} catch (Exception e) {
		}

		return convertView;

	}

	private class ViewHolder {
		private TextView doctorName;
		private TextView doctorTime;
		private RoundedCornerImageView ImageView01;

	}

	public void setPos(int pos) {
		posIndex = pos;
	}

}
